package doubanhongniang
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

import com.google.gdata.client.douban.DoubanService;
import com.google.gdata.data.Link;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.TextContent;
import com.google.gdata.data.douban.Attribute;
import com.google.gdata.data.douban.CollectionEntry;
import com.google.gdata.data.douban.CollectionFeed;
import com.google.gdata.data.douban.MiniblogEntry;
import com.google.gdata.data.douban.MiniblogFeed;
import com.google.gdata.data.douban.NoteEntry;
import com.google.gdata.data.douban.NoteFeed;
import com.google.gdata.data.douban.ReviewEntry;
import com.google.gdata.data.douban.ReviewFeed;
import com.google.gdata.data.douban.Status;
import com.google.gdata.data.douban.Subject;
import com.google.gdata.data.douban.SubjectEntry;
import com.google.gdata.data.douban.SubjectFeed;
import com.google.gdata.data.douban.Tag;
import com.google.gdata.data.douban.TagEntry;
import com.google.gdata.data.douban.TagFeed;
import com.google.gdata.data.douban.UserEntry;
import com.google.gdata.data.douban.UserFeed;
import com.google.gdata.data.extensions.Rating;
import com.google.gdata.util.ServiceException;

class DoubanController {
	def doubanAccessService
    def index = { 
		if (session.oauthToken == null) {
			redirect(uri:"/")
		}
		println params
		def accessToken = params.oauth_token
		UserEntry entry = doubanAccessService.getAuthorizedUser(session.oauthToken.key, session.oauthToken.secret)
		render "finish logon and user is $entry.uid"
		
		/*if (params?.apiUrl) apiUrl = params.apiUrl
		def response = oauthService.accessResource(
		apiUrl, 'linkedin', [key:session.oauthToken.key, secret:session.oauthToken.secret], 'GET')
		render(view: 'index', model: [profileXML: response, apiUrl: apiUrl])*/
	}
    
    def logon = {
    		redirect(url:doubanAccessService.getAuthorizationUrl("http://localhost:8080/doubanhongniang/douban/authorized/"))
    }
	
	def authorized = {
			UserEntry entry = doubanAccessService.authorizedUser
			//def doubanUser = DoubanUser.getOrCreatedAuthorizedUser(entry.uid)
			
			render "finish authorization and user name is ${entry.uid}"
	}
	
}
